Working with Sorting

Changing the existing sort's condition field

For this scenario, a report is created which is currently sorted on the Customer Name field (For example, {Customer.Customer Name}). To change the condition field for the existing field at runtime, the following code can be used:

'General Declarations 
Dim CRXReport As New CrystalReport1 
Dim CRXDatabaseField As CRAXDRT.DatabaseFieldDefinition 
Private Sub Form_Load() 

Currently the sort is based on the Customer Name field and the application is to change it to the Last Year's Sale's field. This field must be present on the report. The code accesses the first table to get the 8th field.

Set CRXDatabaseField = CRXReport.Database.Tables.Item(1).Fields.Item(8) 

There is only one Sort on this report so we will access the first item of the SortFields collection and set the field to the Last Year's Sale's field.

CRXReport.RecordSortFields.Item(1).Field = CRXDatabaseField 
CRViewer1.ReportSource = CRXReport 
CRViewer1.ViewReport 
End Sub 


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com